#pragma once

#include <asm/io.h>

#define CMOS_READ(addr) ({ \
    outb_p(addr | 0x80, 0x70); \
    inb_p(0x71); \
})

/**********************************************************************
 * register summary
 **********************************************************************/
#define RTC_SECONDS       0
#define RTC_SECONDS_ALARM 1
#define RTC_MINUTES       2
#define RTC_MINUTES_ALARM 3
#define RTC_HOURS         4
#define RTC_HOURS_ALARM   5

#define RTC_DAY_OF_WEEK   6
#define RTC_DAY_OF_MONTH  7
#define RTC_MONTH         8
#define RTC_YEAR          9

/* control registers - Moto names
 */
#define RTC_REG_A         10
#define RTC_REG_B         11
#define RTC_REG_C         12
#define RTC_REG_D         13

/**********************************************************************
 * register details
 **********************************************************************/
#define RTC_FREQ_SELECT   RTC_REG_A

#define RTC_UIP           0x80
#define RTC_DIV_CTL       0x70

#define RTC_CONTROL       RTC_REG_B
#define RTC_SET           0x80 /* disable updates for clock setting */
#define RTC_PIE           0x40 /* periodic interrupt enable */
#define RTC_AIE           0x20 /* alarm interrupt enable */
#define RTC_UIE           0x10 /* update-finished interrupt enable */
#define RTC_SQWE          0x08 /* enable square-wave output */
#define RTC_DM_BINARY     0x04 /* all time/date values are BCD if clear */
#define RTC_24H           0x02 /* 24 hour mode - else hours bit 7 means pm */
#define RTC_DST_EN        0x01 /* auto switch DST - works f. USA only */

#ifndef BCD_TO_BIN
#define BCD_TO_BIN(val) ((val) = ((val)&15) + ((val) >> 4) * 10)
#endif
